package com.faxsun.payment.service.gateway;

import javax.annotation.Resource;

import org.broadleafcommerce.common.payment.PaymentType;
import org.broadleafcommerce.common.payment.dto.PaymentRequestDTO;
import org.broadleafcommerce.common.payment.dto.PaymentResponseDTO;
import org.broadleafcommerce.common.payment.service.PaymentGatewayHostedService;
import org.broadleafcommerce.common.vendor.service.exception.PaymentException;
import org.springframework.stereotype.Service;

import com.faxsun.payment.vendor.paysss.service.PaySSSPaymentGatewayType;

@Service("fsPaySSSHostedService")
public class PaySSSHostedService implements PaymentGatewayHostedService {

	@Resource(name = "fsPaySSSHostedConfiguration")
	protected PaymentGatewayHostedConfiguration configuration;

	@Override
	public PaymentResponseDTO requestHostedEndpoint(PaymentRequestDTO requestDTO) throws PaymentException {
		PaymentResponseDTO responseDTO = new PaymentResponseDTO(PaymentType.THIRD_PARTY_ACCOUNT,
				PaySSSPaymentGatewayType.PAYSSS_HOSTED_GATEWAY)
		        .completeCheckoutOnCallback(requestDTO.isCompleteCheckoutOnCallback())
				.responseMap(PaymentGatewayConstants.ORDER_ID, requestDTO.getOrderId())
				.responseMap(PaymentGatewayConstants.ORDER_AMOUNT, requestDTO.getTransactionTotal())
				.responseMap(PaymentGatewayConstants.HOSTED_REDIRECT_URL, configuration.getHostedRedirectUrl());
		return responseDTO;
	}
	
}